<?php

require_once("../private/system/dycms.php");

try {
	
dyInit('/studios/admin.php?$action=browse');


//
// Create the page
//

$page = new cHtmlPage();

$page->AddChild($main = new cHtmlWrapper(<<<HTMLEND
<div class="body">

<div class="headerCtr"><div class="header">
<em>Administration</em>
</div></div>
HTMLEND
	,
	<<<HTMLEND
</div>
HTMLEND
));

$page->AddHtmlHeader(<<<HTMLEND
<link rel="stylesheet" href="assets/style.css" type="text/css" />
<link rel="stylesheet" href="assets/layout.css" type="text/css" />

<script language="JavaScript" type="text/javascript" src="assets/mootools.js"></script>
<script language="JavaScript" type="text/javascript" src="assets/nav.js"></script>
HTMLEND
);

$main->AddChild($cLogo = new cHtmlWrapper('<div class="logo">','</div'));
$cLogo->AddChild(new cHtmlTemplate("StudiosLogo"));

$main->AddChild($cNav = new cHtmlWrapper('<div class="navCtr" style="width: 120px; right: 120px;">','</div>'));


$main->AddChild($cNode = new cHtmlWrapper('<div class="bodyCtr"><div class="bodyMain">', '</div></div>'));

$page->SetContentNode($cNode);
$page->AddModuleContainer($cNav);

$page->AddModule(new cAdminMenuModule());


//
// Process commands
//

if($_GET['$action'] == 'view')
{
	$obj = dyLoadObject($_GET['$clsid'], $_GET['$id']);
	
	if(!($obj instanceof cDycmsObject))
	{
		$queryCls = STDCLS_PAGE;
		$z_queryArgs = array('name'=>'404');
		$runQuery = true;
	};
}
else if($_GET['$action'] == 'page')
{
	$queryCls = STDCLS_PAGE;
	$z_queryArgs = array('site'=>'dyknl','name' => urldecode($_GET['name']));
	$runQuery = true;
}
else if($_GET['$action'] == 'browse')
{
	//
	// Decode arguments
	//
	
	$z_queryArgs = Array();
	foreach($_GET as $s_idx => $s_val)
	{
		if(isset($_GET['$clsid']))
			$queryCls = $_GET['$clsid'];
		
		if($s_idx[0] !== '$')
			$z_queryArgs[urldecode($s_idx)] = urldecode($s_val);
	}
	
	$runQuery = true;
}
else if($_GET['$action'] == 'edit')
{
	if(isset($_GET['$id']))
		$obj = dyLoadObject($_GET['$clsid'], $_GET['$id']);
	else
		$obj = dyCreateObject($_GET['$clsid']);
	
	if(!($obj instanceof cDycmsObject))
	{
		$queryCls = STDCLS_PAGE;
		$z_queryArgs = array('name'=>'404');
		$runQuery = true;
	}
	else
		$edit = true;
}
else
{
	$queryCls = STDCLS_PAGE;
	$z_queryArgs = array('site'=>'admin','name'=>'index');
	$runQuery = true;
};

if($runQuery)
{
	do
	{
		$obj = new cDycmsQuery();
		
		if($queryCls)
			$obj->SetClass($queryCls);
		if($z_queryArgs)
			$obj->AddArray($z_queryArgs);
		
		$n = $obj->Execute();
		
		if(($n === 0) && ($z_queryArgs != array('name'=>'404')))
		{
			$z_queryArgs = array('name'=>'404');
			$queryCls = STDCLS_PAGE;
		}
		else
			break;
	}while(true);
};

if($obj instanceof IDycmsObject)
{
	if($edit)
	{
		$page->sTitle = 'Editing - '.$obj->GetSummary().' - Dynamo CMS';
		$obj->Edit($page);
	}
	else
	{
		$page->sTitle = $obj->GetSummary().' - Dynamo Design Studios';
		$obj->Render($page);
	}
};


//
// Add footer
//

$cNode->AddChild(new cHtmlTemplate("StudiosFooter"));


//
// Initialize modules
//

$page->Display();

dyEnd();

}
catch(Exception $e)
{
	$ex = new cUiException($e);
	$ex->Display();
}

?>
